package tv.geir.slackspace.common;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import tv.geir.slackspace.code.PackageConfiguration;

public class BeanFactory {

	private static ClassPathXmlApplicationContext serverConfig = null;
	private static ClassPathXmlApplicationContext clientConfig = null;
	
	
	private static ApplicationContext serverConfig() {
		if( serverConfig == null ) {
			serverConfig = new ClassPathXmlApplicationContext( BeanConfig.SERVER_SERVICES );
		}
		return serverConfig;
	}
	
	public static Object getServerBean( String name ) {
		return serverConfig().getBean( name );
	}
	
	private static ApplicationContext clientConfig() {
		if( clientConfig == null ) {
			clientConfig = new ClassPathXmlApplicationContext( BeanConfig.CLIENT_SERVICES );
		}
		return clientConfig;
	}
	
	public static Object getClientBean( String name ) {
		return clientConfig().getBean( name );
	}
	
	public static PackageConfiguration getPackageConfiguration() {
		return (PackageConfiguration) clientConfig().getBean( "packageConfiguration" );
	}
		
	
}
